package com.demo.java.concurrent.future;

import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;

import java.util.concurrent.ExecutionException;
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;

public class ThreadDependencyTest {
    public static void main(String[] args) throws ExecutionException, InterruptedException {
        final ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
        executor.initialize();

        Future<Boolean> future = executor.submit(() -> {
            System.out.println("first thread, " + Thread.currentThread().getName());
            TimeUnit.SECONDS.sleep(5);
            return true;
        });

        final Future<Boolean> future1 = executor.submit(() -> {
            try {
                final Boolean preResult = future.get();
                if (!preResult) {
                    return false;
                }
                System.out.println("seconed thread, " + Thread.currentThread().getName());
            } catch (Exception e) {
                e.printStackTrace();
                return false;
            }
            return true;
        });

//        System.out.println(future1.get() + ", " + Thread.currentThread().getName());
        System.out.println(", " + Thread.currentThread().getName());
    }
}
